using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;
using SharpCore.Utilities;

namespace Dating.DA
{
	public class MemberPersonalityDA
	{
		#region Fields

		protected string connectionStringName;

		#endregion

		#region Constructors
		public MemberPersonalityDA()
		{
		}

		public MemberPersonalityDA(string connectionStringName)
		{
			ValidationUtility.ValidateArgument("connectionStringName", connectionStringName);

			this.connectionStringName = connectionStringName;
		}

		#endregion

		#region Methods

		/// <summary>
		/// Saves a record to the MemberPersonality table.
		/// </summary>
		public  int Insert(MemberPersonality memberPersonality)
		{
			ValidationUtility.ValidateArgument("memberPersonality", memberPersonality);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", memberPersonality.TenantID),
				new SqlParameter("@MappingID", memberPersonality.MappingID)
			};

			memberPersonality.ProfileID = Convert.ToInt32(SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "MemberPersonalityInsert", parameters));
			return memberPersonality.ProfileID;
		}

		/// <summary>
		/// Deletes a record from the MemberPersonality table by a foreign key.
		/// </summary>
		public  int DeleteAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberPersonalityDeleteAllByProfileID", parameters));
		}

		/// <summary>
		/// Selects all records from the MemberPersonality table.
		/// </summary>
		public  List<MemberPersonality> SelectAll(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)
			};
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberPersonalitySelectAll", parameters))
			{
				List<MemberPersonality> memberPersonalityList = new List<MemberPersonality>();
				while (dataReader.Read())
				{
					MemberPersonality memberPersonality = MakeMemberPersonality(dataReader);
					memberPersonalityList.Add(memberPersonality);
				}

				return memberPersonalityList;
			}
		}

		/// <summary>
		/// Selects all records from the MemberPersonality table by a foreign key.
		/// </summary>
		public  List<MemberPersonality> SelectAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberPersonalitySelectAllByProfileID", parameters))
			{
				List<MemberPersonality> memberPersonalityList = new List<MemberPersonality>();
				while (dataReader.Read())
				{
					MemberPersonality memberPersonality = MakeMemberPersonality(dataReader);
					memberPersonalityList.Add(memberPersonality);
				}

				return memberPersonalityList;
			}
		}

		/// <summary>
		/// Creates a new instance of the MemberPersonality class and populates it with data from the specified SqlDataReader.
		/// </summary>
		protected  MemberPersonality MakeMemberPersonality(SqlDataReader dataReader)
		{
			MemberPersonality memberPersonality = new MemberPersonality();
			memberPersonality.ProfileID = SqlClientUtility.GetInt32(dataReader, "ProfileID", 0);
			memberPersonality.TenantID = SqlClientUtility.GetInt32(dataReader, "TenantID", 0);
			memberPersonality.MappingID = SqlClientUtility.GetInt32(dataReader, "MappingID", 0);

			return memberPersonality;
		}

		#endregion
	}
}
